package cn.edu.scau.cmi.zhuangzhihong.factorymethod;


		
import cn.edu.scau.cmi.zhuangzhihong.factory.DescriptionPane;
import cn.edu.scau.cmi.zhuangzhihong.factory.InsuranceClaims;
import javafx.application.Application;

// TODO 自动生成的方法存根
		import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
		import javafx.stage.Stage;
		 
		public class mainapp extends Application {
			private Label lblImageTitle = new Label(); 
			private Label message = new Label(); 
			Button show = new Button("显示保险信息");
			
				public void setTitle(String title) {
					lblImageTitle.setText(title);
				 
			}
				
				public void setImageView(ImageView icon) {
					lblImageTitle.setGraphic(icon);
				}
			private String[] InsuranceStyle= {"身体伤害","人员伤亡","汽车损坏","多起事故"};
			
			private String[] InsuranceDescription = new String[5];
			private DescriptionPane descriptionPane = new DescriptionPane();
			
			private ComboBox<String> cbo = new ComboBox<>();
			
			Stage stage = new Stage();
			public void start(Stage primaryStage) throws Exception {
		 
				Factory factory;
				factory=new BodyInjurFactory();
				InsuranceClaims insuranceClaims = factory.InsuranceStyle();
				InsuranceDescription[0]=insuranceClaims.GetLiability();
				
				factory=new CasualtiesFactory();
				insuranceClaims = factory.InsuranceStyle();
				InsuranceDescription[1]=insuranceClaims.GetLiability();
				
				factory=new AutomobileDamageFactory();
				insuranceClaims = factory.InsuranceStyle();
				InsuranceDescription[2]=insuranceClaims.GetLiability();
				
				factory=new MultipleAccidentsFactory();
				insuranceClaims = factory.InsuranceStyle();
				InsuranceDescription[3]=insuranceClaims.GetLiability();
				
				
				setDisplay(0);
				
				BorderPane pane = new BorderPane();
				BorderPane pane2 = new BorderPane();
				
				pane.setCenter(pane2);
				pane.setLeft(lblImageTitle);
				lblImageTitle.setContentDisplay(ContentDisplay.TOP);
				lblImageTitle.setPrefSize(200,100);
				
				message.setText("姓名：     庄生         学号：    201521160235");
				pane2.setTop(message);
				pane2.setBottom(show);
				BorderPane paneForComboBox = new BorderPane();
				paneForComboBox.setLeft(new Label("请选择保险："));
				paneForComboBox.setRight(cbo);
				pane2.setCenter(paneForComboBox);
				cbo.setPrefWidth(400);
				cbo.setValue("身体伤害");
				setDescription(0);
				ObservableList<String> items = FXCollections.observableArrayList(InsuranceStyle);
				cbo.getItems().addAll(items);
				pane.setBottom(descriptionPane);
				
				cbo.setOnAction(e->setDisplay(items.indexOf(cbo.getValue())));
				show.setOnAction(e->setDescription(items.indexOf(cbo.getValue())));
				
				Scene scene = new Scene(pane,700,400);
				primaryStage.setTitle("工厂方法模式");
				primaryStage.setScene(scene);
				primaryStage.show();
				
			}
		 
			private void setDescription(int index) {
				
				descriptionPane.setDescription(InsuranceDescription[index]);
				
			}

			public  void setDisplay(int index) {
				Image image =new Image("file:C:\\Users\\lenovo\\eclipse-workspace\\201521160235庄志宏\\src\\cn\\edu\\scau\\cmi\\zhuangzhihong\\factorymethod\\picture.jpg");
				ImageView imageview = new ImageView();
				imageview.setImage(image);
				setTitle(InsuranceStyle[index]);
				setImageView(imageview);
				
				
			}
			public void  showWindow() throws Exception {
				start(stage);
			}
			public static void main(String[] args) {
		    	
		        launch(args);
		    }

	}


